﻿#include "svglineinfowidget.h"

#include "svgshape.h"
#include "widgets/svgpropinput.h"

#include <QLabel>

SvgLineInfoWidget::SvgLineInfoWidget(QWidget* parent)
	:QWidget(parent)
	, m_startXInput(new SvgPropInput(tr("Start X"), 1000000, 0, this))
	, m_startYInput(new SvgPropInput(tr("Start Y"), 1000000, 0, this))
	, m_endXInput(new SvgPropInput(tr("End X"), 1000000, 0, this))
	, m_endYInput(new SvgPropInput(tr("End Y"), 1000000, 0, this))
	, m_lineWidthInput(new SvgPropInput(tr("LineWidth"), 99.0, 0.1, this))
{
	const auto label = new QLabel(tr("Line: "),this);
	connect(m_lineWidthInput, &SvgPropInput::ValueChanged, this, &SvgLineInfoWidget::ShapeStrokeWidthChanged);
	connect(m_startXInput, &SvgPropInput::ValueChanged, this, &SvgLineInfoWidget::_PosChanged);
	connect(m_startYInput, &SvgPropInput::ValueChanged, this, &SvgLineInfoWidget::_PosChanged);
	connect(m_endXInput, &SvgPropInput::ValueChanged, this, &SvgLineInfoWidget::_PosChanged);
	connect(m_endYInput, &SvgPropInput::ValueChanged, this, &SvgLineInfoWidget::_PosChanged);

	label->setGeometry(0, 0, 150, 30);

	m_startXInput->setGeometry(0, 30, 80, 80);
	m_startYInput->setGeometry(100, 30, 80, 80);
	m_endXInput->setGeometry(0, 130, 80, 80);
	m_endYInput->setGeometry(100, 130, 80, 80);
	m_lineWidthInput->setGeometry(0, 230, 80, 80);
}

void SvgLineInfoWidget::UpdateData(SvgLine& line) const
{
	m_lineWidthInput->SetValue(line.Pen().widthF());
	m_startXInput->SetValue(line.Line().p1().x());
	m_startYInput->SetValue(line.Line().p1().y());
	m_endXInput->SetValue(line.Line().p2().x());
	m_endYInput->SetValue(line.Line().p2().y());
}

void SvgLineInfoWidget::_PosChanged(double)
{
	emit LinePosChanged(QLineF(m_startXInput->Value(), m_startYInput->Value(),
		m_endXInput->Value(), m_endYInput->Value()));
}
